package com.linghang.lhonline.service.Impl;

import com.linghang.lhonline.dataobject.GroupType;
import com.linghang.lhonline.repository.GroupTypeRepository;
import com.linghang.lhonline.service.GroupTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GroupTypeServiceImpl implements GroupTypeService {

    private GroupTypeRepository groupTypeRepository;

    @Autowired
    public GroupTypeServiceImpl(GroupTypeRepository groupTypeRepository) {
        this.groupTypeRepository = groupTypeRepository;
    }

    @Override
    public List<String> groupList() {
        List<GroupType> groupTypeList = groupTypeRepository.findAll();

        List<String> list = new ArrayList<>();

        for (GroupType groupType : groupTypeList) {
            list.add(groupType.getGroupName());
        }

        return list;
    }

    @Override
    public GroupType save(GroupType groupType) {
        return groupTypeRepository.save(groupType);
    }

    @Override
    public GroupType findByGroupName(String groupName) {
        return groupTypeRepository.findByGroupName(groupName);
    }

    @Override
    public void delete(GroupType groupType) {
        groupTypeRepository.delete(groupType);
    }
}
